<template>
  <div class="grad-container">
    <h3>等级配置</h3>
    <el-form ref="formRef" :model="form" :rules="formRules" label-width="150px">
      <el-form-item label="团长：" prop="geNumPeople">
        <el-input v-model="form.geNumPeople" placeholder="请输入"></el-input>
        （团队下激活人数大于等于目标值升级为此等级）
      </el-form-item>
      <el-form-item prop="numDirectReferrals">
        <el-input
          v-model="form.numDirectReferrals"
          placeholder="请输入"
        ></el-input>
        （直推人数）
      </el-form-item>
      <el-form-item prop="consumerStandards">
        <el-input
          v-model="form.consumerStandards"
          placeholder="请输入"
        ></el-input>
        （消费金额）
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="saveForm()">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import seviceApi from '@/api/serviceApi.js'
export default {
  data() {
    return {
      form: {},
      formRules: {
        geNumPeople: {
          required: true,
          message: '团队下激活人数大于等于目标值升级为此等级不能为空',
          trigger: 'blur'
        },
        numDirectReferrals: {
          required: true,
          message: '直推人数不能为空',
          trigger: 'blur'
        },
        consumerStandards: {
          required: true,
          message: '消费金额不能为空',
          trigger: 'blur'
        }
      }
    }
  },
  created () {
    this.getInfo()
  },
  methods: {
    getInfo () {
      seviceApi.getIntegralGradInfo().then(res => {
        if (res && res.data.code === 200) {
          this.form = res.data.data
        }
      })
    },
    saveForm () {
      this.$refs.formRef.validate(valid => {
        if (valid) {
          seviceApi.saveIntegralGrad(this.form).then(res => {
            if (res && res.data.code === 200) {
              this.getInfo()
              this.$message.success('保存成功')
            }
          })
        } else {
          this.$message.error('请将表单补充完整')
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.grad-container {
  /deep/ .el-form {
    .el-form-item__label {
      font-weight: bold;
    }
    .el-input {
      width: 300px;
    }
    .el-input-number--medium {
      width: 300px;
    }
    .remark {
      margin-left: 20px;
    }
  }
}
</style>
